﻿using Microsoft.Owin;
using Owin;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Hangfire;
using Hangfire.LiteDB;

[assembly: OwinStartup(typeof(FE.PDFConvert.Tools.Startup))]

namespace FE.PDFConvert.Tools
{
    public class Startup
    {
        private IEnumerable<IDisposable> GetHangfireServers()
        {
            GlobalConfiguration.Configuration
                .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                .UseSimpleAssemblyNameTypeSerializer()
                .UseRecommendedSerializerSettings()
                .UseLiteDbStorage(@"d:\tmp\pdf\fePdfJobs.db");

            yield return new BackgroundJobServer();
        }

        public void Configuration(IAppBuilder app)
        {
            app.UseHangfireAspNet(GetHangfireServers);
            app.UseHangfireDashboard();

            // Let's also create a sample background job
            //BackgroundJob.Enqueue(() => Debug.WriteLine("Hello world from Hangfire!"));

            //RecurringJob.AddOrUpdate(() => Debug.WriteLine("Hello recurring job from Hangfire every minutes!"), "* * * * *");



            //recurringJobManager.AddOrUpdate(
            //    "run every minutes",
            //    () => Console.WriteLine("recurring job !"),
            //    "* * * * *"
            //);

            // ...other configuration logic
        }
    }
}
